package cz.muni.fi.pa165.musiclibrary.musiclibraryweb;

import org.apache.wicket.core.request.handler.ListenerInterfaceRequestHandler;
import org.apache.wicket.core.request.mapper.MountedMapper;
import org.apache.wicket.request.IRequestHandler;
import org.apache.wicket.request.Url;
import org.apache.wicket.request.component.IRequestablePage;
import org.apache.wicket.request.mapper.info.PageComponentInfo;
import org.apache.wicket.request.mapper.parameter.PageParametersEncoder;

/**
 * Page mapper that does not provider page info (page id, render count, etc.).
 * 
 * @author Maros Kucbel
 * @date 2012-11-25T14:36:08+0100
 */
public final class CleanUrlMapper extends MountedMapper {

    public CleanUrlMapper(String mountPath, Class<? extends IRequestablePage> pageClass) {
        super(mountPath, pageClass, new PageParametersEncoder());
    }
    
    /**
     * do nothing so that component info does not get rendered in url 
     */    
    @Override
    protected void encodePageComponentInfo(Url url, PageComponentInfo info) {
        
    }

    @Override
    public Url mapHandler(IRequestHandler requestHandler) {
        if (requestHandler instanceof ListenerInterfaceRequestHandler) {
            return null;
        } else {
            return super.mapHandler(requestHandler);
        }
    }
}